﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using Campus.Main.Basic.Settings;
using Campus.Report.ReportForm;
using Microsoft.Reporting.WinForms;
using cpmntctrl;
using dbcntn;
using mkrpt;

namespace Campus.Main.Basic
{
    public partial class AllListK : DefaultForm
    {
        protected ConnectionToDb _aToDb;
        protected string query = "select count(student_id) from kmaintable ";
        public AllListK()
        {
            InitializeComponent();
            _aToDb=new ConnectionToDb(Helper.ConnectionString);
            MaximizeBox = false;
        }

        protected virtual void AllList_Load(object sender, EventArgs e)
        {
            radioButton1.Checked = true;
            _aToDb.AddItemDBGridView(dataGridView1, Query.KesinKayit);
            toolStripStatusLabel2.Text = _aToDb.SelectField(query);
        }

        protected virtual void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                dataGridView1.DataSource = null;
                _aToDb.AddItemDBGridView(dataGridView1, Query.KesinKayit);
                toolStripStatusLabel2.Text = _aToDb.SelectField(query);
            }
        }

        protected virtual void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            string temp1=Query.KesinKayit, temp2=query;
            if (radioButton2.Checked)
            {
                temp1 += " and a.pol_id=1";
                dataGridView1.DataSource = null;
                _aToDb.AddItemDBGridView(dataGridView1, temp1);
                toolStripStatusLabel2.Text = _aToDb.SelectField(temp2+=" where pol_id=1");
            }
        }

        protected virtual void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            string temp1 = Query.KesinKayit, temp2 = query;
            if (radioButton3.Checked)
            {
                dataGridView1.DataSource = null;
                _aToDb.AddItemDBGridView(dataGridView1, temp1 += " and a.pol_id=2");
                toolStripStatusLabel2.Text = _aToDb.SelectField(temp2+=" where pol_id=2");
            }
        }

        protected virtual void button1_Click(object sender, EventArgs e)
        {
            string query1 = Query.KesinKayit;
            if (radioButton2.Checked)
            {
                query1 += " and a.pol_id=1";
            }
            if (radioButton3.Checked)
            {
                query1 += " and a.pol_id=2";
            }
            ReportForm f = new ReportForm();
            f.reportViewer1.ProcessingMode=ProcessingMode.Local;
            f.reportViewer1.LocalReport.ReportPath = "ReportTemplate/KesinkayitReport.rdlc";
            ogrenci2006_dboDataSet1.Clear();
            f.reportViewer1.LocalReport.DataSources.Clear();
            f.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", _aToDb.GetDataSources(ogrenci2006_dboDataSet1, "kmaintable", query1)));
            f.ShowDialog();
        }

        protected virtual void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
           // MessageBox.Show(Convert.ToString(dataGridView1[e.ColumnIndex, e.RowIndex].Value));
        }

        protected virtual void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
                return;
            List<string> data = new List<string>();
            ControlComponent.AddToList(data, dataGridView1, e, 0);
            KKayit f = new KKayit(data[0]);
            f.FormClosed += child_FormClosed;
            Hide();
            f.ShowDialog();
        }
        private void child_FormClosed(object sender, FormClosedEventArgs e)
        {
            Close();
        }
    }
}
